//
//  BackgroundTaskController.swift
//  TTProduct-iOS
//
//  Created by Toj on 11/9/21.
//

import UIKit
import AVFoundation

class BackgroundTaskController: STBaseViewController {
    
    /**  后台进程id */
    private var backgroudTaskId:UIBackgroundTaskIdentifier?

    override func viewDidLoad() {
        super.viewDidLoad()

        NotificationCenter.default.addObserver(self, selector: #selector(applicationDidEnterBackground), name: UIApplication.didEnterBackgroundNotification, object: nil)
    }
    
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        
    let vc = STTVViewController()
        present(vc, animated: true, completion: nil)
    }
    
    @objc func applicationDidEnterBackground(){
        backgroudTaskId = UIApplication.shared.beginBackgroundTask(withName: "com.startimes.ios.AppRunInBackground", expirationHandler: {
           
            if self.backgroudTaskId != .invalid{
                UIApplication.shared.endBackgroundTask(self.backgroudTaskId!)
                self.backgroudTaskId = .invalid
            }
            
            // print("rhjkl")
        })
    }
}

